package golf;

import golf.Character.CharacterGrade;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import database.DAO;


public class Item {
	int no;
	String name;
	String category_name;
	int req_property_no;
	int effect_property_no;
	int buy_price;
	int sell_price;
	int repair_price;
	int sale_price;
	int basic_durability;
//	int curr_durability;
	char repair_YN;
	int req_character_grade_no;
//	String req_character_grade_nm;
	int req_model_no;
//	String req_model_nm;
	int req_level;
	
	Property req_property;
	Property effect_property;
	
	Model req_model;
	Character.CharacterGrade req_character_grade;

	public Item(){}
	public Item(ResultSet rs){
		/*
		 * ITEMNO
		ITEMNM
		ITEMREQPROPNO
		ITEMEFFECTPROPNO
		ITEMBUYPRICE
		ITEMBASICDUR
		CURRDUR
		ITEMREPAIRAVAILYN
		ITEMREPAIRPRICE
		ITEMSELLPRICE
		ITEMSALEPRICE
		ITEMREQCHARGRADENO
		ITEMREQCHARGRADENO
		ITEMREQMODELNO
		ITEMREQMODELNM
		ITEMREQLEVEL
		ITEMCATENM
		 */
		try {
			setNo( rs.getInt("ITEMNO") );
			setName(rs.getString("ITEMNM"));
			setCategory_name(rs.getString("ITEMCATENM"));
			setReq_property_no(rs.getInt("ITEMREQPROPNO"));
			setEffect_property_no(rs.getInt("ITEMEFFECTPROPNO"));
			setBuy_price(rs.getInt("ITEMBUYPRICE"));
			setSell_price(rs.getInt("ITEMSELLPRICE"));
			setRepair_price(rs.getInt("ITEMREPAIRPRICE"));
			setSale_price(rs.getInt("ITEMSALEPRICE"));
			setBasic_durability(rs.getInt("ITEMBASICDUR"));
			setRepair_YN(rs.getString("ITEMREPAIRAVAILYN").charAt(0));
			setReq_character_grade_no(rs.getInt("ITEMREQCHARGRADENO"));
			setReq_model_no(rs.getInt("ITEMREQMODELNO"));
			setReq_level(rs.getInt("ITEMREQLEVEL"));
	
			DAO dao = DAO.getInstance();
			if(getReq_property_no() != 0)
				setReq_property(dao.getProperty(getReq_property_no()));
			if(getEffect_property_no() != 0)
				setEffect_property(dao.getProperty(getEffect_property_no()));
			if(getReq_model_no() != 0)
				setReq_model(dao.getModel(getReq_model_no()));
			if(getReq_character_grade_no() != 0)
				setReq_character_grade(dao.getCharacterGrade(getReq_character_grade_no()));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	public String getReqPropertyString(){
		if(req_property == null) return "없음";
		String result = "";
		result += req_property.getPower() + "/";
		result += req_property.getImpact() + "/";
		result += req_property.getTechnique() + "/";
		result += req_property.getStamina();
		return  result;
	}
	public String getEffectPropertyString(){
		if(effect_property == null) return "없음";
		String result = "";
		result += effect_property.getPower() + "/";
		result += effect_property.getImpact() + "/";
		result += effect_property.getTechnique() + "/";
		result += effect_property.getStamina();
		return  result;		
	}
	
	public int getNo() {
		return no;
	}
	public void setNo(int no) {
		this.no = no;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCategory_name() {
		return category_name;
	}
	public void setCategory_name(String category_name) {
		this.category_name = category_name;
	}
	public int getReq_property_no() {
		return req_property_no;
	}
	public void setReq_property_no(int req_property_no) {
		this.req_property_no = req_property_no;
	}
	public int getEffect_property_no() {
		return effect_property_no;
	}
	public void setEffect_property_no(int effect_property_no) {
		this.effect_property_no = effect_property_no;
	}
	public int getBuy_price() {
		return buy_price;
	}
	public void setBuy_price(int sell_price) {
		this.sell_price = sell_price;
	}
	public int getSell_price() {
		return sell_price;
	}
	public void setSell_price(int sell_price) {
		this.sell_price = sell_price;
	}
	public int getRepair_price() {
		return repair_price;
	}
	public void setRepair_price(int repair_price) {
		this.repair_price = repair_price;
	}
	public int getSale_price() {
		return sale_price;
	}
	public void setSale_price(int sale_price) {
		this.sale_price = sale_price;
	}
	public int getBasic_durability() {
		return basic_durability;
	}
	public void setBasic_durability(int basic_durability) {
		this.basic_durability = basic_durability;
	}
	public char getRepair_YN() {
		return repair_YN;
	}
	public void setRepair_YN(char repair_YN) {
		this.repair_YN = repair_YN;
	}
	public int getReq_character_grade_no() {
		return req_character_grade_no;
	}
	public void setReq_character_grade_no(int req_character_grade_no) {
		this.req_character_grade_no = req_character_grade_no;
	}
	
	public int getReq_model_no() {
		return req_model_no;
	}
	public void setReq_model_no(int req_model_no) {
		this.req_model_no = req_model_no;
	}
	public int getReq_level() {
		return req_level;
	}
	public void setReq_level(int req_level) {
		this.req_level = req_level;
	}
	
	public Property getReq_property() {
		return req_property;
	}
	public void setReq_property(Property req_property) {
		this.req_property = req_property;
	}
	public Property getEffect_property() {
		return effect_property;
	}
	public void setEffect_property(Property effect_property) {
		this.effect_property = effect_property;
	}	
	public Model getReq_model() {
		return req_model;
	}
	public void setReq_model(Model req_model) {
		this.req_model = req_model;
	}
	public Character.CharacterGrade getReq_character_grade() {
		return req_character_grade;
	}
	public void setReq_character_grade(Character.CharacterGrade req_character_grade) {
		this.req_character_grade = req_character_grade;
	}
	
}
